package com.workManager.service;

import com.workManager.mapper.TbDirectEstimateMapper;
import com.workManager.pojo.TbDirectEstimate;
import com.workManager.util.DateUtil;
import com.workManager.util.WebUtil;
import com.workManager.vo.DierctEstimateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by stran on 2017/11/1 0001.
 */
@Service
public class DirectEstimateServiceImpl implements DirectEstimateService{

    @Autowired
    private TbDirectEstimateMapper directEstimateMapper;

    public List<DierctEstimateVo> query(Map map) {
        return directEstimateMapper.query(map);
    }

    public void add(TbDirectEstimate directEstimate) {
        if(null!=directEstimate.getRemark()&&!"".equals(directEstimate.getRemark())){
            directEstimate.setRemark("["+ DateUtil.getDate()+":"+ WebUtil.getCurrentUserVO().getUserName()+"]:"+directEstimate.getRemark());
        }
        directEstimateMapper.add(directEstimate);
    }

    public void invalid(TbDirectEstimate directEstimate) {
        Map map = new HashMap();
        String remarkArr[] = directEstimate.getRemark().split("\\|");
        String remark = remarkArr[0]+"|["+ DateUtil.getDate()+":"+ WebUtil.getCurrentUserVO().getUserName()+"]:"+remarkArr[1];
        map.put("remark", remark);
        map.put("id", directEstimate.getId());
        directEstimateMapper.invalid(map);
    }

}
